package com.caszx.chargingpile.holder.reservate;

import android.view.View;
import android.widget.TextView;

import com.app.base.adapter.holder.BaseHolder;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.entity.EntityCommPile;
import com.caszx.chargingpile.eventbus.OfenReservateStation;

import java.text.DecimalFormat;

import de.greenrobot.event.EventBus;


public class OftenUseHolder extends BaseHolder<EntityCommPile> implements View.OnClickListener{

    private TextView  txtTitle;
    private TextView  txtDistance;
    private TextView  txtInfo;
    private TextView  txt_priceAc;
    private TextView  txt_stopcarFee;
    private TextView  txt_serverFeeAc;
    private TextView  btn_reservate;
    private TextView  btn_delete;

    private static DecimalFormat decimalFormat = new DecimalFormat("###.##");
    public OftenUseHolder(View view) {
        super(view);
    }

    @Override
    protected void initView() {
        txtTitle = (TextView) mRootView.findViewById(R.id.txtTitle);
        txtDistance = (TextView) mRootView.findViewById(R.id.txtDistance);
        txtInfo = (TextView) mRootView.findViewById(R.id.txtInfo);
        txt_priceAc = (TextView) mRootView.findViewById(R.id.txt_priceAc);
        txt_stopcarFee = (TextView) mRootView.findViewById(R.id.txt_stopcarFee);
        txt_serverFeeAc = (TextView) mRootView.findViewById(R.id.txt_serverFeeAc);
        btn_reservate = (TextView) mRootView.findViewById(R.id.btn_reservate);
        btn_delete = (TextView) mRootView.findViewById(R.id.btn_delete);
    }

    @Override
    protected void refreshView() {
        txtTitle.setText(mItem.stationName);
        txtDistance.setText(decimalFormat.format(mItem.distence/1000)+"Km");
        txtInfo.setText(mItem.fastRuningPile+"个快充 "+mItem.slowRuningPile+"个慢充");
        txt_priceAc.setText("充电费"+mItem.priceAc+"元/度");
        txt_stopcarFee.setText("停车费"+mItem.stopcarFee+"元/小时");
        txt_serverFeeAc.setText("服务费"+mItem.stopcarFee+"元/次");

        btn_reservate.setOnClickListener(this);
        btn_delete.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_reservate:
                EventBus.getDefault().post(new OfenReservateStation(false,mItem.stationId,mItem.stationName,mPosition));
                break;
            case R.id.btn_delete:
                EventBus.getDefault().post(new OfenReservateStation(true,mItem.stationId,mItem.stationName,mPosition));
                break;
        }
    }
}
